package 递归实现排列类型枚举2;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static int N = 10, n;
    static int[] a = new int[N];
    static boolean[] st = new boolean[N];
    static int[] nums = new int[N];
    static BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        Arrays.sort(a, 0, n);
        dfs(0);
        writer.flush();
    }

    private static void dfs(int u) throws IOException {
        if (u == n) {
            for (int i = 0; i < n; i++) {
                writer.write(nums[i] + " ");
            }
            writer.newLine();
            return;
        }
        for (int i = 0; i < n; i++) {
            if (!st[i]) {
                nums[u] = a[i];
                st[i] = true;
                dfs(u + 1);
                nums[u] = 0;
                st[i] = false;
                while (i < n && a[i + 1] == a[i]) {
                    i++;
                }
            }
        }
    }
}
